package cn.com.headfree.welfare.service.impl;

import cn.com.headfree.welfare.entity.FlRegistrationdeath;
import cn.com.headfree.welfare.entity.FlSoftTransfer;
import cn.com.headfree.welfare.dao.FlSoftTransferDao;
import cn.com.headfree.welfare.service.FlSoftTransferService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (FlSoftTransfer)表服务实现类
 *
 * @author makejava
 * @since 2021-12-21 14:54:01
 */
@Service("flSoftTransferService")
public class FlSoftTransferServiceImpl implements FlSoftTransferService {
    @Resource
    private FlSoftTransferDao flSoftTransferDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FlSoftTransfer queryById(Integer id) {
        return this.flSoftTransferDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<FlSoftTransfer> queryAllByLimit(int offset, int limit) {
        return this.flSoftTransferDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param flSoftTransfer 实例对象
     * @return 实例对象
     */
    @Override
    public FlSoftTransfer insert(FlSoftTransfer flSoftTransfer) {
        if(flSoftTransfer.getLcdwmcId()!=null){
            flSoftTransfer.setLcdwmc(flSoftTransferDao.getOrgName(flSoftTransfer.getLcdwmcId()));
        }
        if(flSoftTransfer.getLrdwId()!=null){
            flSoftTransfer.setLrdw(flSoftTransferDao.getOrgName(flSoftTransfer.getLrdwId()));
        }
        if(flSoftTransfer.getStjfId()!=null){
            flSoftTransfer.setStjf(flSoftTransferDao.getOrgName(flSoftTransfer.getStjfId()));
        }
        this.flSoftTransferDao.insert(flSoftTransfer);
        return flSoftTransfer;
    }

    /**
     * 修改数据
     *
     * @param flSoftTransfer 实例对象
     * @return 实例对象
     */
    @Override
    public FlSoftTransfer update(FlSoftTransfer flSoftTransfer) {
        if(flSoftTransfer.getLcdwmcId()!=null){
            flSoftTransfer.setLcdwmc(flSoftTransferDao.getOrgName(flSoftTransfer.getLcdwmcId()));
        }
        if(flSoftTransfer.getLrdwId()!=null){
            flSoftTransfer.setLrdw(flSoftTransferDao.getOrgName(flSoftTransfer.getLrdwId()));
        }
        if(flSoftTransfer.getStjfId()!=null){
            flSoftTransfer.setStjf(flSoftTransferDao.getOrgName(flSoftTransfer.getStjfId()));
        }
        this.flSoftTransferDao.update(flSoftTransfer);
        return this.queryById(flSoftTransfer.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.flSoftTransferDao.deleteById(id) > 0;
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param flSoftTransfer 实例对象
     * @return 对象列表
     */
    @Override
    public PageInfo<FlSoftTransfer> queryAll(FlSoftTransfer flSoftTransfer){
        PageHelper.startPage(flSoftTransfer.getPage(), flSoftTransfer.getPageSize());
        flSoftTransfer.setDelSign(0);
        List<FlSoftTransfer> list =this.flSoftTransferDao.queryAll(flSoftTransfer);
        PageInfo<FlSoftTransfer> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }


}
